﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract Proveedores typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class ProveedoresDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<ProveedoresDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.Proveedores _currentProveedores = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxProveedoresDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxProveedoresErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxProveedoresBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IdProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the NombreProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNombreProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DireccionProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDireccionProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the TelefonoProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTelefonoProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ContactoProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxContactoProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the CorreoContactoProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxCorreoContactoProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the RtnProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxRtnProveedorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the EstadoProveedor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxEstadoProveedorDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.Proveedores> _ProveedoresList;
				
		/// <summary> 
		/// The list of Proveedores to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.Proveedores> ProveedoresList
		{
			get {return this._ProveedoresList;}
			set
			{
				this._ProveedoresList = value;
				this.uxProveedoresBindingSource.DataSource = null;
				this.uxProveedoresBindingSource.DataSource = value;
				this.uxProveedoresDataGridView.DataSource = null;
				this.uxProveedoresDataGridView.DataSource = this.uxProveedoresBindingSource;				
				//this.uxProveedoresBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxProveedoresBindingSource_ListChanged);
				this.uxProveedoresBindingSource.CurrentItemChanged += new System.EventHandler(OnProveedoresBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnProveedoresBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentProveedores = uxProveedoresBindingSource.Current as Entities.Proveedores;
			
			if (_currentProveedores != null)
			{
				_currentProveedores.Validate();
			}
			//_Proveedores.Validate();
			OnCurrentEntityChanged();
		}

		//void uxProveedoresBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.Proveedores"/> instance.
		/// </summary>
		public Entities.Proveedores SelectedProveedores
		{
			get {return this._currentProveedores;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxProveedoresDataGridView.VirtualMode;}
			set
			{
				this.uxProveedoresDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxProveedoresDataGridView.AllowUserToAddRows;}
			set {this.uxProveedoresDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxProveedoresDataGridView.AllowUserToDeleteRows;}
			set {this.uxProveedoresDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxProveedoresDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxProveedoresDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="ProveedoresDataGridViewBase"/> class.
		/// </summary>
		public ProveedoresDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxProveedoresDataGridView = new System.Windows.Forms.DataGridView();
			this.uxProveedoresBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxProveedoresErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNombreProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDireccionProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxTelefonoProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxContactoProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxCorreoContactoProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxRtnProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxEstadoProveedorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxProveedoresErrorProvider
			// 
			this.uxProveedoresErrorProvider.ContainerControl = this;
			this.uxProveedoresErrorProvider.DataSource = this.uxProveedoresBindingSource;						
			// 
			// uxProveedoresDataGridView
			// 
			this.uxProveedoresDataGridView.AutoGenerateColumns = false;
			this.uxProveedoresDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxProveedoresDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdProveedorDataGridViewColumn,
		this.uxNombreProveedorDataGridViewColumn,
		this.uxDireccionProveedorDataGridViewColumn,
		this.uxTelefonoProveedorDataGridViewColumn,
		this.uxContactoProveedorDataGridViewColumn,
		this.uxCorreoContactoProveedorDataGridViewColumn,
		this.uxRtnProveedorDataGridViewColumn,
		this.uxEstadoProveedorDataGridViewColumn			});
			this.uxProveedoresDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxProveedoresDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxProveedoresDataGridView.Name = "uxProveedoresDataGridView";
			this.uxProveedoresDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxProveedoresDataGridView.TabIndex = 0;	
			this.uxProveedoresDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxProveedoresDataGridView.EnableHeadersVisualStyles = false;
			this.uxProveedoresDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnProveedoresDataGridViewDataError);
			this.uxProveedoresDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnProveedoresDataGridViewCellValueNeeded);
			this.uxProveedoresDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnProveedoresDataGridViewCellValuePushed);
			
			//
			// uxIdProveedorDataGridViewColumn
			//
			this.uxIdProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdProveedorDataGridViewColumn.DataPropertyName = "IdProveedor";
			this.uxIdProveedorDataGridViewColumn.HeaderText = "IdProveedor";
			this.uxIdProveedorDataGridViewColumn.Name = "uxIdProveedorDataGridViewColumn";
			this.uxIdProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdProveedorDataGridViewColumn.ReadOnly = true;		
			//
			// uxNombreProveedorDataGridViewColumn
			//
			this.uxNombreProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNombreProveedorDataGridViewColumn.DataPropertyName = "NombreProveedor";
			this.uxNombreProveedorDataGridViewColumn.HeaderText = "NombreProveedor";
			this.uxNombreProveedorDataGridViewColumn.Name = "uxNombreProveedorDataGridViewColumn";
			this.uxNombreProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNombreProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNombreProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxDireccionProveedorDataGridViewColumn
			//
			this.uxDireccionProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDireccionProveedorDataGridViewColumn.DataPropertyName = "DireccionProveedor";
			this.uxDireccionProveedorDataGridViewColumn.HeaderText = "DireccionProveedor";
			this.uxDireccionProveedorDataGridViewColumn.Name = "uxDireccionProveedorDataGridViewColumn";
			this.uxDireccionProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDireccionProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDireccionProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxTelefonoProveedorDataGridViewColumn
			//
			this.uxTelefonoProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTelefonoProveedorDataGridViewColumn.DataPropertyName = "TelefonoProveedor";
			this.uxTelefonoProveedorDataGridViewColumn.HeaderText = "TelefonoProveedor";
			this.uxTelefonoProveedorDataGridViewColumn.Name = "uxTelefonoProveedorDataGridViewColumn";
			this.uxTelefonoProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTelefonoProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTelefonoProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxContactoProveedorDataGridViewColumn
			//
			this.uxContactoProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxContactoProveedorDataGridViewColumn.DataPropertyName = "ContactoProveedor";
			this.uxContactoProveedorDataGridViewColumn.HeaderText = "ContactoProveedor";
			this.uxContactoProveedorDataGridViewColumn.Name = "uxContactoProveedorDataGridViewColumn";
			this.uxContactoProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxContactoProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxContactoProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxCorreoContactoProveedorDataGridViewColumn
			//
			this.uxCorreoContactoProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxCorreoContactoProveedorDataGridViewColumn.DataPropertyName = "CorreoContactoProveedor";
			this.uxCorreoContactoProveedorDataGridViewColumn.HeaderText = "CorreoContactoProveedor";
			this.uxCorreoContactoProveedorDataGridViewColumn.Name = "uxCorreoContactoProveedorDataGridViewColumn";
			this.uxCorreoContactoProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxCorreoContactoProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxCorreoContactoProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxRtnProveedorDataGridViewColumn
			//
			this.uxRtnProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxRtnProveedorDataGridViewColumn.DataPropertyName = "RtnProveedor";
			this.uxRtnProveedorDataGridViewColumn.HeaderText = "RtnProveedor";
			this.uxRtnProveedorDataGridViewColumn.Name = "uxRtnProveedorDataGridViewColumn";
			this.uxRtnProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxRtnProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxRtnProveedorDataGridViewColumn.ReadOnly = false;		
			//
			// uxEstadoProveedorDataGridViewColumn
			//
			this.uxEstadoProveedorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxEstadoProveedorDataGridViewColumn.DataPropertyName = "EstadoProveedor";
			this.uxEstadoProveedorDataGridViewColumn.HeaderText = "EstadoProveedor";
			this.uxEstadoProveedorDataGridViewColumn.Name = "uxEstadoProveedorDataGridViewColumn";
			this.uxEstadoProveedorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxEstadoProveedorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxEstadoProveedorDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxProveedoresDataGridView);
			this.Name = "ProveedoresDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxProveedoresBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				ProveedoresDataGridViewEventArgs args = new ProveedoresDataGridViewEventArgs();
				args.Proveedores = _currentProveedores;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class ProveedoresDataGridViewEventArgs : System.EventArgs
		{
			private Entities.Proveedores	_Proveedores;
	
			/// <summary>
			/// the  Entities.Proveedores instance.
			/// </summary>
			public Entities.Proveedores Proveedores
			{
				get { return _Proveedores; }
				set { _Proveedores = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxProveedoresDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnProveedoresDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxProveedoresDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnProveedoresDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxProveedoresDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].IdProveedor;
						break;
					case "uxNombreProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].NombreProveedor;
						break;
					case "uxDireccionProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].DireccionProveedor;
						break;
					case "uxTelefonoProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].TelefonoProveedor;
						break;
					case "uxContactoProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].ContactoProveedor;
						break;
					case "uxCorreoContactoProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].CorreoContactoProveedor;
						break;
					case "uxRtnProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].RtnProveedor;
						break;
					case "uxEstadoProveedorDataGridViewColumn":
						e.Value = ProveedoresList[e.RowIndex].EstadoProveedor;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxProveedoresDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnProveedoresDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxProveedoresDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].IdProveedor = (System.Int32)e.Value;
						break;
					case "uxNombreProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].NombreProveedor = (System.String)e.Value;
						break;
					case "uxDireccionProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].DireccionProveedor = (System.String)e.Value;
						break;
					case "uxTelefonoProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].TelefonoProveedor = (System.String)e.Value;
						break;
					case "uxContactoProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].ContactoProveedor = (System.String)e.Value;
						break;
					case "uxCorreoContactoProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].CorreoContactoProveedor = (System.String)e.Value;
						break;
					case "uxRtnProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].RtnProveedor = (System.String)e.Value;
						break;
					case "uxEstadoProveedorDataGridViewColumn":
						ProveedoresList[e.RowIndex].EstadoProveedor = (System.Int32?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
